﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class LibraryController : ControllerBase
    {
        private readonly DZJDBcontext db;
        /// <summary>
        /// 数据库
        /// </summary>

        public LibraryController(DZJDBcontext context)
        {
            db = context;
        }
        [HttpGet]
        public List<EM_Library> GetAll()
        {
            //select * from EM_Library 查找
            return db.EM_Library.ToList();
        }
        [HttpPost]
        public bool Add(EM_Library em_Library)
        {
            //sql insert into  set EM_Library xuehao=20  班级活动人数增加
            db.EM_Library.Add(em_Library);

            int result = db.SaveChanges();
            return result > 0 ? true : false;
        }

        [HttpDelete]
        public bool Delete(Guid ID)
        {
            EM_Library? em_Library = new EM_Library();
            em_Library = db.EM_Library.Where(a => a.xuehao == 210122).SingleOrDefault();

            int result = 0;
            if (em_Library != null)
            {
                //sql update...
                db.EM_Library.Remove(em_Library);
                result = db.SaveChanges();
            }



            return result > 0 ? true : false;
        }

    }
}
